<?php 
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');

$currCat = get_the_category();
$parent = get_cat_name($currCat[0]->category_parent);
//redirect to child if is archive for top-level parent
if ( is_category( $parent ) ) { 
	first_subcat_redirect();
}

get_header(); ?>


  <div id="content">
    <div class="wrap">

      <div class="column column-narrow">
      
      	<?php 
      	
    	echo "<p class='heading'>".$parent."</p>";
    	
		/*if ($current !== 'Classes') {
		list_cat_posts_all();
		}*/
		
		list_cat_posts_all();
		?>
      
        <?php 

        if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Archive Pages') ) : ?>&nbsp;<?php endif; 
        ?>
        
        <?php
        $currCat = get_the_category();
		$currCatID = $currCat[0]->cat_ID;
		$parentid = $currCat[0]->parent;
		
        if (function_exists('echo_meebome') && $parentid == "60") echo_meebome(); 
        
        ?>
        
        
      </div><!-- end .column-narrow -->
      
      <div class="column column-content column-double column-last">
	  	<div id="crumbs">
			<!--?php the_breadcrumb(); ?-->
			<?php
				$args = array(
					'prefix' => '<p>',
					'suffix' => '</p>',
					'title' => __( '', 'breadcrumbs-plus' ),
					'home' => __( 'Home', 'breadcrumbs-plus' ),
					'sep' => '»',
					'front_page' => false,
					'bold' => true,
					'show_blog' => false,
					'echo' => true,
					'singular_post_taxonomy' => 'category',
				);
				breadcrumbs_plus( $args );
			?>
		</div>
		
		<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
		<?php /* If this is a category archive */ if (is_category()) { ?>
		<h1><?php single_cat_title(); ?></h1>
		<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
		<h1>Archive for: <?php single_tag_title(); ?></h1>
		<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
		<h1>Archive for <?php the_time('F jS, Y'); ?></h1>
		<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
		<h1>Archive for <?php the_time('F, Y'); ?></h1>
		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
		<h1>Archive for <?php the_time('Y'); ?></h1>
		<?php /* If this is an author archive */ } ?>
      
      <div class="posts">
		<ul style="display:none" class="GTTabs" id="GTTabs_ul_32">
			<li class="GTTabs_curr" id="GTTabs_li_0_32"><a class="GTTabsLinks" onmouseout="GTTabsShowLinks();" onmouseover="GTTabsShowLinks('Current Classes'); return true;" id="32_0">Current Classes</a></li>
			<li id="GTTabs_li_1_32" class=""><a class="GTTabsLinks" onmouseout="GTTabsShowLinks();" onmouseover="GTTabsShowLinks('Future Classes'); return true;" id="32_1">Future Classes</a></li>
			<li id="GTTabs_li_2_32" class=""><a class="GTTabsLinks" onmouseout="GTTabsShowLinks();" onmouseover="GTTabsShowLinks('Future Classes'); return true;" id="32_2">Special Courses</a></li>
			<li id="GTTabs_li_3_32" class=""><a class="GTTabsLinks" onmouseout="GTTabsShowLinks();" onmouseover="GTTabsShowLinks('List of Classes'); return true;" id="32_3">List of Classes</a></li>
		</ul>
		<div id="GTTabs_0_32" class="GTTabs_divs GTTabs_curr_div" style="display: block;">
			<span class="GTTabs_titles"><b>Current Classes</b></span>
			<?php
				if( function_exists( 'class_calendar' ) ) {
					class_calendar(); 
				}
			?>
		</div>
		<div id="GTTabs_1_32" class="GTTabs_divs" style="display: none;">
			<span class="GTTabs_titles"><b>Future Classes</b></span>
			<?php
				if( function_exists( 'class_calendar_future' ) ) {
					class_calendar_future(); 
				}
			?>
		</div>
		<div id="GTTabs_2_32" class="GTTabs_divs" style="display: none;">
			<span class="GTTabs_titles"><b>Special Courses</b></span>
			<?php
				if( function_exists( 'class_calendar_future' ) ) {
					class_calendar_special(); 
				}
			?>
		</div>
		<div id="GTTabs_3_32" class="GTTabs_divs" style="display: none;">
			<span class="GTTabs_titles"><b>List of Classes</b></span>

	<?php //if ($currCatID == "13") echo "<div style='width: 500px; background-color: #ccc; padding: 10px 40px;'>".do_shortcode( '[contact-form 1 "Contact form 1"]' )."</div><br/><br/>"; ?>

  <?php
  wp_reset_query();
    $wp_query->set('orderby', 'title');  
    $wp_query->set('order', 'ASC'); 
    $wp_query->get_posts();  

  $i = 0;
  if (have_posts()) : while (have_posts()) : the_post();
  $i++;
  update_post_caches($posts);
  ?>
      
        <div class="post">
        
        <?php 
        unset($img);

				if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
						$attachedFile = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
            $img = $attachedFile[0]; 
						}
				
				else{ 
				 
          if ($proud_cf_use == 'Yes')
          {
            $img = get_post_meta($post->ID, $proud_cf_photo, true);
          } // if CF used
          else
          {
            if (!$img)
            {
              $img = catch_that_image($post->ID);
            }
          } // if CF not used
        }
          
          if ($img)
          {
            ?>
            <div class="thumb"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=80&amp;w=120&amp;zc=1&amp;src=<?php echo $img ?>" alt="<?php the_title(); ?>" class="bordered" /></a></div>
            <?php 
          }

    ?>
    <?php 
		$cert = get('required_detail_cert_class'); 
		if ( $cert == 'Yes' ) { $certcheck = true;  }
		
		//permanent course information, not conditional
		$perm_class_info= get_group('Permanent Course Information'); // use the Custom Group name
		if (!is_null($perm_class_info)) {
			foreach($perm_class_info as $perm_info) {
				//assign each field a variable name
				$refNumber = $perm_info['permanent_info_reference_number'][1];
				$courseNumber = $perm_info['permanent_info_course_number'][1];
			//end foreach permclassinfo as perminfo
			}
		//end if not null permclassinfo
		}
		
	?>
          <h2>
          	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
          		<?php 
          			the_title();
          			if (($refNumber != 'n/a' && $refNumber != 'N/A') || ($courseNumber != 'n/a' && $courseNumber != 'N/A')) {
          				if ($refNumber != '') {
	          				echo ' &ndash; <em>'.$refNumber.'</em>';
	          			}
	          			else if ($courseNumber != '') {
	          				echo ' &ndash; <em>'.$courseNumber.'</em>';
	          			}
          			}
          			if ( $cert == 'Yes' ) { echo "&nbsp;*"; }
          		?>
          	</a>
          </h2>
          <div class="info">
          <?php $excerpt= get('permanent_info_catalogue_description'); echo magic_excerpt($excerpt , '[...]');?>
          </div>
        
          <div class="clear">&nbsp;</div>  

        </div><!-- end .post -->

        <?php endwhile; 
        
        else:
        
        ?>
        <h2>Sorry, there are no posts in this category.</h2>
        <?php
        
        endif; ?>
        
        	<div class="mock-tags"><?php if ( $certcheck ) { $category_id = get_cat_ID( 'Graduate Certificate' ); $category_link = get_category_link( $category_id );echo "<span style='font-weight: bold;'>*</span>&nbsp;Counts toward fulfillment of <a href='".$category_link."' title='Graduate Certificate' >Graduate Certificate</a> Program"; } ?></div>
        
        </div>
	  
      <div class="navigation">
      <p><span class="older"><?php next_posts_link('&lt; older entries') ?></span>  <span class="latest"><?php previous_posts_link('newer entries &gt;') ?></span></p>
      </div>

      </div><!-- end .posts -->
      
      </div><!-- end .column-content -->
      
      <div class="clear">&nbsp;</div>

    </div><!-- end .wrap -->
  </div><!-- end #content -->

<?php get_footer(); ?>
